import { Injectable } from '@angular/core';

import { Subject } from 'rxjs/Subject';

@Injectable()

export class MessageProvider {

    op = new Subject();

    emit(key, param) {
        this.op.next({ "key": key, "param": param});
    }

    // 
    subscribe(key, callback) {
        return this.op.filter((data) => {
            return data['key'] == key;
        }).subscribe((data) => {
            callback(data);
        });
    }

    destory() {
        this.op.unsubscribe();
    }


}